package com.atguigu.eud_teacher.dao;
import com.atguigu.eud_teacher.entity.CourseEntity;
import com.atguigu.eud_teacher.vo.CourseInfoVo;
import com.atguigu.eud_teacher.vo.CoursePublishVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 课程
 *
 * @author wuyao
 * @email 13918471632@163.com
 * @date 2021-03-23 12:12:26
 */
@Mapper

public interface CourseDao extends BaseMapper<CourseEntity> {

    @Select(" SELECT\n" +
            "            course.id,\n" +
            "            course.lesson_num AS lessonNum,\n" +
            "            course.cover,\n" +
            "            course.price,\n" +
            "            course.title,\n" +
            "            teacher.`name` AS teacherName,\n" +
            "            des.description,\n" +
            "            sub1.title AS subjectLevelOne,\n" +
            "            sub2.title AS subjectLevelTwo\n" +
            "        FROM\n" +
            "            edu_course AS course\n" +
            "                LEFT JOIN edu_teacher AS teacher ON course.teacher_id = teacher.id\n" +
            "                LEFT JOIN edu_subject AS sub1 ON course.subject_parent_id = sub1.id\n" +
            "                LEFT JOIN edu_subject AS sub2 ON course.subject_id = sub2.id\n" +
            "                LEFT JOIN edu_course_description AS des ON course.id = des.id\n" +
            "        WHERE\n" +
            "            course.id = #{id}\n")
    CoursePublishVo getFinalResult(String id);


    @Select("SELECT\n" +
            "\tcourse.id,\n" +
            "\tcourse.lesson_num AS lessonNum,\n" +
            "\tcourse.cover,\n" +
            "\tcourse.price,\n" +
            "\tcourse.title,\n" +
            "  course.buy_count as buyCount,\n" +
            "  course.view_count as viewCount,\n" +
            "  teacher.id as teacherId,\n" +
            "\tteacher.`name` AS teacherName,\n" +
            "  teacher.avatar as avatar,\n" +
            "  teacher.career as career,\n" +
            "  teacher.intro as intro,\n" +
            "  teacher.`level` as teacherLevel,\n" +
            "\tdes.description,\n" +
            "  sub1.id as subjectLevelOneId,\n" +
            "\tsub1.title AS subjectLevelOne,\n" +
            "\tsub2.id AS subjectLevelTwoId,\n" +
            "  sub2.title AS subjectLevelTwo\n" +
            "   \n" +
            "FROM\n" +
            "\tedu_course AS course\n" +
            "LEFT JOIN edu_teacher AS teacher ON course.teacher_id = teacher.id\n" +
            "LEFT JOIN edu_subject AS sub1 ON course.subject_parent_id = sub1.id\n" +
            "LEFT JOIN edu_subject AS sub2 ON course.subject_id = sub2.id\n" +
            "LEFT JOIN edu_course_description AS des ON course.id = des.id\n" +
            "WHERE\n" +
            "\tcourse.id = #{id}")
    CourseInfoVo getBaseCourseInfo(String courseId);

    @Select("SELECT\n" +
            "\tcourse.id AS courseId,\n" +
            "\tcourse.lesson_num AS lessonNum,\n" +
            "\tcourse.cover,\n" +
            "\tcourse.price,\n" +
            "\tcourse.title,\n" +
            "  course.buy_count as buyCount,\n" +
            "  course.view_count as viewCount,\n" +
            "  teacher.id as teacherId,\n" +
            "\tteacher.`name` AS teacherName,\n" +
            "  teacher.avatar as avatar,\n" +
            "  teacher.career as career,\n" +
            "  teacher.intro as intro,\n" +
            "  teacher.`level` as teacherLevel,\n" +
            "\tdes.description,\n" +
            "  sub1.id as subjectLevelOneId,\n" +
            "\tsub1.title AS subjectLevelOne,\n" +
            "\tsub2.id AS subjectLevelTwoId,\n" +
            "  sub2.title AS subjectLevelTwo\n" +
            "   \n" +
            "FROM\n" +
            "\tedu_course AS course\n" +
            "LEFT JOIN edu_teacher AS teacher ON course.teacher_id = teacher.id\n" +
            "LEFT JOIN edu_subject AS sub1 ON course.subject_parent_id = sub1.id\n" +
            "LEFT JOIN edu_subject AS sub2 ON course.subject_id = sub2.id\n" +
            "LEFT JOIN edu_course_description AS des ON course.id = des.id\n" +
            "WHERE\n" +
            "\tcourse.id = #{id}")
    //courseid找不到，我重新写了一个给了一个别名，上面不改是怕后面接口有问题
    CourseInfoVo getBaseCourseInfoo(String courseId);
}
